package com.haiyou.dc.mq.task;

import com.haiyou.dc.mq.bi.RabbitMqService;
import com.haiyou.dc.mq.entity.Product;
import com.haiyou.dc.mq.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.CountDownLatch;

/**
 * @author huangzl
 */
@Slf4j
@Component
public class PersonThread {

    @Autowired
    private RabbitMqService rabbitMqService;
    private static int mobile = 0;

    /**
     * 线程数量
     */
    public static final int THREAD_NUM = 50000;

    public void init() {
        CountDownLatch countDownLatch = new CountDownLatch(1);
        for (int i = 0; i < THREAD_NUM; i++) {
            new Thread(() -> {
                try {
                    countDownLatch.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                mobile += 1;
                rabbitMqService.sendProductMessage(String.valueOf(mobile));
                log.info("----------------->{}", Thread.currentThread().getName());
            }).start();
        }
        countDownLatch.countDown();
    }


}
